package org.geometerplus.fbreader.book;


import com.example.administrator.fangbook.dataLibrary.book.ShelfItemBook;
import com.example.administrator.fangbook.read.bean.Chapter;

import org.geometerplus.fbreader.formats.BookReadingException;
import org.geometerplus.fbreader.formats.FormatPlugin;
import org.geometerplus.fbreader.formats.IChapterReadBook;
import org.geometerplus.fbreader.formats.txt.MTxtReader;
import org.geometerplus.zlibrary.core.filesystem.ZLTxtFile;
import org.geometerplus.zlibrary.text.view.ZLTextPosition;

public class MTxtBook extends ReadBook implements IChapterReadBook {


    private ShelfItemBook book;

    public MTxtReader getReader() {
        return (MTxtReader) myBookReader;
    }

    public void setReader(MTxtReader reader) {
        myBookReader = reader;
    }

    public MTxtBook(ZLTxtFile file, FormatPlugin plugin) throws BookReadingException {
        super(file, plugin);
        setTitle(file.getBookName());
        book = file.getShelfBook();
    }

    public MTxtBook(long id, ZLTxtFile file, String title, String encoding, String language) {
        super(id, file, title, encoding, language);
        book = file.getShelfBook();
    }


    public void storePosition(ZLTextPosition position) {
        MTxtReader reader = (MTxtReader) myBookReader;
        Chapter readingChapter = reader != null ? reader.getReadingChapter() : null;
        if (position != null && readingChapter != null) {
            position.setTag(readingChapter.getId());
        }
        super.storePosition(position);
    }

    public String getBookId() {
        return ((ZLTxtFile) File).getFullPath();
    }

    public String getChapterId() {
        return ((ZLTxtFile) File).getChapterId();
    }

    public ShelfItemBook getShelfBook() {
        return book;
    }

}
